package com.bw.zg2.http

import okhttp3.Interceptor
import okhttp3.OkHttpClient
import okhttp3.Response
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.create
import java.util.concurrent.TimeUnit

/**
 *
 * @ClassName: HttpUtil
 * @Description: 单例网络工具类
 * @Author: zhangyanchao
 * @CreateDate: 2024/9/12 12:07 PM
 * @Version: 1.0
 */

object HttpUtil {
    const val BASE_URL = "http://10.161.9.80:7012/"
    val retrofit = Retrofit.Builder()
        .baseUrl(BASE_URL)
        .client(
            OkHttpClient().newBuilder()
                .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                .addInterceptor(TokenInterceptor())
                .connectTimeout(5, TimeUnit.MINUTES)
                .retryOnConnectionFailure(true)
                .build()
        )
        .addConverterFactory(GsonConverterFactory.create())
        .build()

    //获取apiService
    val apiService = retrofit.create<ApiService>()
}